
minetest.register_craftitem(
	"lightball:lightball",
	{
		description="Lightball",
		inventory_image="lightball_lightball.png",
		on_use=function(itemstack, player, pointed_thing)
			local ps=player:get_pos()
			ps.y=ps.y+1
			local entity=minetest.add_entity(ps,"lightball:lightball_flying",nil)
			if entity then
				local lv=player:get_look_dir()
				lv.x=20*lv.x
				lv.y=20*lv.y
				lv.z=20*lv.z
				entity:set_velocity(lv)
			end
			itemstack:take_item(1)
			return itemstack
		end
	}
)

minetest.register_node(
	"lightball:air",
	{
		description="Light Air",
		drawtype="airlike",
		paramtype="light",
		sunlight_propagates=true,
		walkable=false,
		pointable=false,
		diggable=false,
		buildable_to=true,
		air_equivalent=true,
		drop="",
		groups={not_in_creative_inventory=1},
		light_source=14,
		on_construct=function(pos)
			minetest.get_node_timer(pos):start(5.0)
		end,
		on_timer=function(pos)
			minetest.set_node(pos,{name="air"})
		end
	}
)

minetest.register_entity(
	"lightball:lightball_flying",
	{
		visual="sprite",
		textures={"lightball_lightball.png"},
		is_visible=true,
		collisionbox={-0.2,-0.2,-0.2,0.2,0.2,0.2},
		collide_with_objects=true,
		on_step=function(self,dtime)
			local ps=self.object:get_pos()
			if minetest.get_node(ps).name=="air" then
				minetest.set_node(ps,{name="lightball:air"})
			elseif minetest.get_node(ps).name=="lightball:air" then
			else
				self.object:remove()
			end
		end
	}
)

minetest.register_craft(
	{
		type="shaped",
		output="lightball:lightball 33",
		recipe={
			{"","default:mese_crystal_fragment",""},
			{"","default:torch",""},
			{"","",""},
		}
	}
)
